package com.googlecode.sere.translation

case class MediaType(
  mainType: String,
  subType: String,
  params: Map[String, String] = Map()) {
  
  if (params.contains("q"))
    throw new IllegalArgumentException("%s: \"q\" is not allowed as a param" format (MediaType.invalid))

  // TODO: Check for valid chars
}

object MediaType {

  val invalid = "Invalid media type"
  
  def parse(string: String) = {
    MediaRange.parse(string) match {
      case (Some(mainType), Some(subType)) => (mainType, subType)
      case _ => throw new Exception("%s: %s" format (invalid, string))
    }
  }
}
